package app

import (
	"chatgpt/model/base"
	"github.com/slclub/go-tips"
	"strconv"
)

// gorm.io/gorm
type User struct {
	UUID      string
	Cell      string `gorm:"index;size:20;comment:'手机号'"` //index;unique;size(50);description(用户名)
	Login     string `gorm:"size:128;comment:登陆id"`
	Wechat    string `gorm:"index;type:varchar(64);comment:'微信'"` // open id
	Sex       int    `gorm:"type:int(8)"`
	NickName  string `gorm:"index;unique;size:50;comment:'昵称'"`
	Passwd    string `gorm:"size:64"`
	Avatar    string `gorm:"size:128;column:avatar"`
	Remark    string `gorm:"size:256;"`
	Birth     int    `gorm:"type:int(10)"` // 生日
	Level     int    `gorm:"type:int(10);comment:会员等级"`
	Frozen    int
	LoginAt   string `gorm:"size:22;comment:登陆时间"`
	UsrType   string `gorm:"size:20;comment:用户类型"`
	CashTotal int    `gorm:"type:int(10);comment:充值总金额，货币单位分"`
	CashLeft  int    `gorm:"type:int(10);comment:剩余总金额"`
	base.ModelTime
}

//
//func (this *User) TableName() string {
//	return "gpt_user"
//}

func (this *User) ConvFromMap(usr_map map[string]any) {
	if val, ok := usr_map["UUID"]; ok && this.UUID == "" {
		this.UUID = tips.String(val)
	}
	if val, ok := usr_map["Cell"]; ok {
		this.Cell = tips.String(val)
	}
	if val, ok := usr_map["Login"]; ok {
		this.Login = tips.String(val)
	}
	if val, ok := usr_map["Wechat"]; ok {
		this.Wechat = tips.String(val)
	}
	if val, ok := usr_map["Sex"]; ok {
		this.Sex = tips.Int(val)
	}
	if val, ok := usr_map["Passwd"]; ok {
		this.Passwd = tips.String(val)
	}
	if val, ok := usr_map["Avatar"]; ok {
		this.Avatar = tips.String(val)
	}
	if val, ok := usr_map["Remark"]; ok {
		this.Remark = tips.String(val)
	}
	if val, ok := usr_map["NickName"]; ok {
		this.NickName = tips.String(val)
	}
	if val, ok := usr_map["Birth"]; ok {
		this.Birth = int(tips.Any2Int64(val))
	}
	if val, ok := usr_map["Level"]; ok {
		this.Level = int(tips.Any2Int64(val))
	}
	if val, ok := usr_map["Frozen"]; ok {
		this.Frozen = int(tips.Any2Int64(val))
	}
	if val, ok := usr_map["LoginAt"]; ok {
		this.LoginAt = tips.String(val)
	}
	if val, ok := usr_map["UsrType"]; ok {
		this.UsrType = tips.String(val)
	}
	if val, ok := usr_map["CashTotal"]; ok {
		this.CashTotal = tips.Int(val)
	}
	if val, ok := usr_map["CashLeft"]; ok {
		this.CashLeft = tips.Int(val)
	}
	this.ModelTime.ConvFromMap(usr_map)
}

func (this *User) ConvToMap() map[string]any {
	usr_map := make(map[string]any)
	usr_map["UUID"] = this.UUID
	usr_map["Cell"] = (this.Cell)
	usr_map["Wechat"] = this.Wechat
	usr_map["Sex"] = strconv.Itoa(this.Sex)
	usr_map["NickName"] = this.NickName
	usr_map["Passwd"] = this.Passwd
	usr_map["Remark"] = this.Remark
	usr_map["Avatar"] = this.Avatar
	usr_map["LoginAt"] = (this.LoginAt)
	usr_map["Login"] = (this.Login)
	usr_map["Birth"] = this.Birth
	usr_map["Level"] = this.Level
	usr_map["Frozen"] = this.Frozen
	usr_map["UsrType"] = this.UsrType
	usr_map["CashTotal"] = this.CashTotal
	usr_map["CashLeft"] = this.CashLeft

	this.ModelTime.ConvToMap(usr_map)
	return usr_map
}
